<?php
include_once("../db_connect.php");

$name =  mysql_real_escape_string(htmlentities(trim($_GET['name'])));
$email =  mysql_real_escape_string(htmlentities(trim($_GET['email'])));
$subject =  mysql_real_escape_string(htmlentities(trim($_GET['subject'])));
$text = mysql_real_escape_string(htmlentities(trim($_GET['content'])));
$view = "no";
$sql = mysql_query("SELECT * FROM tbl_account where type='1' AND id='1' limit 1")or die(mysql_error());
$row = mysql_fetch_assoc($sql);
$to = $row['email'];


$message = '

<html>
	<body>
		<p>Email: '.$email.'</p>
		<p>Name: '.$name.'</p>
		</br> <p align="justify">' .$text. '</p>
	</body>
</html>';



	
	
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$headers .= "From: admin@basciautosales.zz.mu\r\nReply-To: ".$email." ";
// Additional headers



$mail_sent = @mail( $to, $subject, $message, $headers );
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" 



$sql = mysql_query("INSERT INTO tblmessage(fromemail,message,subject,view)VALUES('".$email."','".$text."','".$subject."','".$view."') ")or die(mysql_error());
if(mysql_affected_rows()){
echo $mail_sent ? "sent" : "failed";
}
else{
	echo $sql;
}


?>